/*!
 * Copyright (c) 2010 WangYang
 * Registration Forms Authentication.
 * Date: 2010-09-14 20:42:16
 */
var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
var passwdtest = /^[a-zA-Z0-9_]{6,16}$/;
var nametest = /[a-zA-Z][a-zA-Z0-9|_]{2,19}$/;

function trim(val){
	return val.replace(/(\s*$)/g, "");
}

function checkUserrand(){
	var userrand1 = trim($("#userrand1").attr("value"));
	if( userrand1 == ''){
		$("#Prompt").attr("className","wrong");$("#Cue").attr("className","wrong_c");
		$("#Prompt").show();$("#Cue").show();
		$("#Cue").html("请输入验证码!");
		return false;
	}else if( $('#userrand1').val().length != 4){
		$("#Prompt").attr("className","wrong");$("#Cue").attr("className","wrong_c");
		$("#Prompt").show();$("#Cue").show();
		$("#Cue").html("请输入正确的验证码!");
		return false;
	}else{
		$("#Prompt").hide();$("#Cue").hide();
		return true;
	}
}

function Check_User_Login(){
    if(!checkUserrand()) return false;

	return true;

}

function formSub(){
	if(trim($("#user_name").attr("value")) == ''){
	alert("==========");
		$("#L_wrong").attr("className","l_wrong");
		$("#L_wrong").show();
		$("#L_wrong").html("请输入用户名!");
		return false;
	}else if( !nametest.test(trim($("#user_name").attr("value"))) ){
		$("#L_wrong").attr("className","l_wrong");
		$("#L_wrong").show();
		$("#L_wrong").html("用户名格式不正确!");
		return false;
	}else{
		$("#L_wrong").hide();
	}
	if(trim($("#passwd").attr("value")) == ''){
		$("#L_wrong").attr("className","l_wrong");
		$("#L_wrong").show();
		$("#L_wrong").html("请输入密码!");
		return false;
	}else if(!passwdtest.test(trim($("#passwd").attr("value")))) {
		$("#L_wrong").attr("className","l_wrong");
		$("#L_wrong").show();
		$("#L_wrong").html("密码必须大于6位，请重新输入!");
		return false;
	}else{
		$("#L_wrong").hide();
	}
	if(trim($("#userrand").attr("value")) == ''){
		$("#L_wrong").attr("className","l_wrong");
		$("#L_wrong").show();
		$("#L_wrong").html("请输入验证码!");
		return false;
	}else if( $('#userrand').val().length != 4){
		$("#L_wrong").attr("className","l_wrong");
		$("#L_wrong").show();
		$("#L_wrong").html("请输入正确的验证码!");
		return false;
	}else{
		$("#L_wrong").hide();
	}
	
	//document.loginForm.submit();
}

document.onkeydown = keyDown;

function keyDown(e){
	if((e ? e.which : event.keyCode)==13 ){
			formSub();
	}


}